<?php
namespace app\api\controller;

use app\common\controller\IndexBaseController;
use app\web\model\OrderItemsModel;
use app\web\model\OrderCarModel;
use app\web\model\OrderModel;
use think\Db;
/**
 * 商品处理
 */
class OrderController extends IndexBaseController {
	protected function _initialize() {
		parent::_initialize();
		
	}
	 	   /* 
	 * 获取订单
	 */
	public function orders(){
		$data=input("post.");
		if($data['type']==1){//个人
			$where['user_id']=$data['uid'];
		}
		$where['status']=1;
		if($data['type']==2){//商家
			//根据用户id获取商家信息
			$agent_info =  db('mall_agent')->where('u_id',$data['uid'])->find();
			if($agent_info){
				$where['agent_id']=$agent_info['id'];
			}else{
				return json(['code'=>406,'msg'=>'店铺不存在']);
			}
		}
		if($data['status']!=""){//订单状态
			$where['order_state']=$data['status'];
		}
		$list=db("mall_order")->where($where)->select();
		$list1=array();
		if($list){
			foreach($list as $k=>$v){
				$list1[$v['id']]=$v;
			}
			$order_ids = array_keys($list1);
			$order_items = db("mall_order_item")->where("order_id","in",$order_ids)->order('add_time desc')->select();
			foreach($order_items as $k1=>$v1){
				 $list1[$v1['order_id']]['items'][]=$v1;
			}
		}
		$code=404;
		if($list1){
			$code=200;
			array_multisort($list1,SORT_DESC);
		}
		return $this->toJson($code, '',$list1);
	}
	/**
	 * 收货
	 */
	public function shouhuo(){
		$where['id']=input("id");
		$where['user_id']=input("user_id");
		$data['receive_time']=now_time();
		$data['order_state']=5;
		$model=new OrderModel();
		$res=db('mall_order')->where($where)->update($data);
		$model->order_complete(input("id"));
		
		//获取订单信息
		$shou_order = db('mall_order')->where('id',input("id"))->find();
		//获取用户信息
		$shou_user = db('member')->where('id',input("user_id"))->find();
		//更新用户信息
		$this->order_done($shou_order,$shou_user);
		
		if($res){
			return json(['code'=>200,'msg'=>'收货成功','id'=>input("id")]);
		}else{
			return json(['code'=>406,'msg'=>'收货失败']);
		}
	}
	//关闭订单
	public function order_close(){
		$data['order_state']=input("status");
		$res=db('mall_order')->where("id",input("id"))->update($data);
		if($res){
			return json(['code'=>200,'msg'=>'操作成功']);
		}else{
			return json(['code'=>406,'msg'=>'操作失败']);
		}
	}
	/**
	 * 删除
	 */
	public function del_order(){
		$order_id=input('id');
		$res=db('mall_order')->where("id",$order_id)->update(["status"=>2]);
		if($res){
			return json(['code'=>200,'msg'=>'操作成功']);
		}else{
			return json(['code'=>406,'msg'=>'操作失败']);
		}		
	}
	/**
	 * 获取订单信息
	 */
	public function getOrderInfo(){
		$order=db("mall_order")->where('id',input("id"))->find();
		$order_items = db("mall_order_item")->where("order_id",input("id"))->select();
		$order['items']=$order_items;
		return json(['data'=>$order]);
	}
		//确认消费
	public function order_xiaofei(){
		$data['order_state']=5;
		$res=db('mall_order')->where("id",input("id"))->update($data);
		$model=new OrderModel();
		$model->order_complete(input("id"));
		//获取订单信息
		$xiaofei_order = db('mall_order')->where('id',input("id"))->find();
		//获取用户信息
		$xiaofei_user = db('member')->where('id',$xiaofei_order['user_id'])->find();
		//更新用户信息
		$this->order_done($xiaofei_order,$xiaofei_user);
		if($res){
			return json(['code'=>200,'msg'=>'操作成功']);
		}else{
			return json(['code'=>406,'msg'=>'操作失败']);
		}
	}
	
	/**
	 * 生成订单
	 */
	 public function creteOrder($goodsInfo,$userInfo,$goods_num){
	 	
		$detail = $this->getDetailPrice($goodsInfo,$goods_num);
		
		if(!is_null($detail)){
			//获取上级代理
			$level2 = Db::name("member")->where('id', $userInfo['pid'])->value('pid');
			$level3 = Db::name("member")->where('id', $level2)->value('pid');
			
			//获取店铺合伙人id
			$storeUid = Db::name("mall_agent")->where('id', $goodsInfo['agent_id'])->value('u_id');
			$pt_id =Db::name("member")->where('id', $storeUid)->value('pt_id');
			
			//获取分佣信息
			$site = Db::name("mall_setting")->where("key","distribution")->find();
			$site = iunserializer($site['value']);
			
		 	//生成订单
			$newOrder=new OrderModel();
			$newOrder->agent_id 	= $goodsInfo['agent_id'];
			$newOrder->order_state 	= 1;
			$newOrder->user_id 		= $userInfo['id'];
			$newOrder->total_price 	= $detail['total_price'];
			$newOrder->postage 		= $goodsInfo['postage'];
			$newOrder->order_time 	= now_time();
			$newOrder->sn 			= order_create_no();
			$newOrder->express_type = intval($goodsInfo['goods_type']) ==1 ? 2 : 1;
			$newOrder->co_id 		= $userInfo['co_id'];
			$newOrder->pt_id 		= $pt_id;
			$newOrder->level1 		= $userInfo['pid'];
			$newOrder->level2 		= $level2;
			$newOrder->level3 		= $level3;
			$newOrder->goods_lanmu  = $goodsInfo['goods_lanmu'];
			$newOrder->level1_money = (floatval($site['commission1'])*100 * $detail['total_price'])/10000;
			$newOrder->level2_money = (floatval($site['commission2'])*100 * $detail['total_price'])/10000;
			$newOrder->level3_money = (floatval($site['commission3'])*100 * $detail['total_price'])/10000;
			$newOrder->pt_money  	= (floatval($site['ptagentcommission'])*100 * $detail['total_price'])/10000;
			$newOrder->co_money  	= (floatval($site['cityagentcommission'])*100 * $detail['total_price'])/10000;
			$newOrder->give_score	= $detail['give_score'];
			$newOrder->need_score	= $detail['needScore'];
			$newOrder->pay_price 	= $detail['total_price'];
		}
		
		return $newOrder;
	 }

	/**
	 * 生成订单详情
	 */
	 public function createOrderItem($goodsInfo,$useInfo,$goods_num){
	 	
		$detail = $this->getDetailPrice($goodsInfo,$goods_num);
		
		if(!is_null($detail)){
			//生成订单详情
			$newItem = new OrderItemsModel();
			$newItem->goods_id		=  $goodsInfo['id'];
			$newItem->goods_name	=  $goodsInfo['name'];
			$newItem->price			=  $detail['price'];
			$newItem->weight		=  $goodsInfo['weight'];
			$newItem->number		=  $goods_num;
			$newItem->thumb			=  $goodsInfo['thumb'];
			$newItem->postage		=  $goodsInfo['postage'];
			$newItem->agent_id		=  $goodsInfo['agent_id'];
			$newItem->add_time		=  now_time();
			$newItem->need_score	=  $detail['needScore'];
			$newItem->goods_lanmu	=  $goodsInfo['goods_lanmu'];
			$newItem->user_id		=  $useInfo['id'];
			$newItem->total_price	=  $detail['total_price'];
			$newItem->give_score	=  $detail['give_score'];
		}
		return $newItem;
	 }
	 
	/**
	  * 创建订单
	  */
	  public  function addOrder(){
	  	$goods_type = request() -> param('goods_type');
		$goods_id = request() -> param('goods_id');
		$goods_num = request() -> param('goods_num');
		$user_id = request() -> param('uid');
		
		//获取用户信息
		$userInfo = Db::name("member")->where('id', $user_id)->find();
		
		//获取商品信息
		$goodsTable = $this->getNumType($goods_type);
		$goodsInfo = Db::name($goodsTable)->where('id', $goods_id)->find();
		
		
		$newOrder = $this->creteOrder($goodsInfo,$userInfo,$goods_num);
		$newItem  = $this->createOrderItem($goodsInfo,$userInfo,$goods_num);
		
		// 启动事务
		Db::startTrans();
		try {
			    $result1 = $newOrder->allowField(true)->save();
				$newOrder_id = $newOrder-> id;
				
				$newItem->order_id = $newOrder_id;
				$result2 = $newItem->allowField(true)->save();
				$newItem_id = $newItem-> id;
				
		    // 提交事务
		    Db::commit();
			
			if(!empty($newOrder_id) && !empty($newItem_id)){
				$OrderInfo['Order_id'] = $newOrder_id;
				//$OrderInfo['Item_id'] = $newItem_id;
				
				
				return $this -> toJson(200, '', $OrderInfo);
			}else{
				return $this -> toJson(405, '数据异常');
			}
		} catch (Exception $e) {
		    Db::rollback();
		}
	}




	/**
	 * 获取订单信息
	 */
	public function getorder(){
		$order_id = request() -> param('order_id');
		$user_id = request() -> param('uid');
		
		//获取订单信息
		$orderInfo = Db::name("mall_order")->where('id', $order_id)->find();

		if($orderInfo){
			//获取订单详情
			$orderItem = Db::name("mall_order_item")->where('order_id', $order_id)->find();
			
			//获取用户地址
			$addressList = Db::name("mall_address")->where('uid', $user_id)->select();
			
			if(!empty($orderItem) && !empty($addressList)){
				$buyInfo['orderInfo'] = $orderInfo;
				$buyInfo['orderItem'] = $orderItem;
				$buyInfo['addressList'] = $addressList;
				
				return $this -> toJson(200, '', $buyInfo);
			}else{
				return $this -> toJson(405, '数据异常');
			}
			
		}else{
			return $this -> toJson(400, '非法访问');
		}
	}
	
	/**
	 * 购物车订单信息
	 */
	public function getOrderCart(){
		$order_ids = request() -> param('order_ids');
		$user_id = request() -> param('user_id');
		
		$order_ids = explode("|", $order_ids); 
		
		
		//获取订单信息
		$orderInfos = Db::name("mall_order")->where('id','in',$order_ids)->select();

		if($orderInfos){
			//获取订单详情
			$orderItem = Db::name("mall_order_item")->where('order_id','in', $order_ids)->select();
			
			//获取用户地址
			$addressList = Db::name("mall_address")->where('uid', $user_id)->select();
			
			if(!empty($orderItem) && !empty($addressList)){
				$buyInfo['orderInfo'] = $orderInfos;
				$buyInfo['orderItem'] = $orderItem;
				$buyInfo['addressList'] = $addressList;
				
				return $this -> toJson(200, '', $buyInfo);
			}else{
				return $this -> toJson(405, '数据异常');
			}
			
		}else{
			return $this -> toJson(400, '非法访问');
		}
	}
	
	//用户付款操作
	public function updOrder(){
		$address_id = request() -> param('address_id');
		$order_ids = request() -> param('order_ids');
		$order_mes = request() -> param('order_mes');
		$payType = request() -> param('pay_type');
		
		//获取用户地址
		$addressInfo = Db::name("mall_address")->where('id', $address_id)->find();
		
		
		$orderInfo = Db::name("mall_order")->where('id',$order_ids)->find();
		
		$result=null;

		if($orderInfo){
			$orderInfo['pay_type'] 			= $payType;
			$orderInfo['pay_mode'] 			= 0;
			$orderInfo['pay_time'] 			= now_time();
			$orderInfo['receiver'] 			= $addressInfo['realname'];
			$orderInfo['receiver_mobile'] 	= $addressInfo['mobile'];
			$orderInfo['province'] 			= $addressInfo['province'];
			$orderInfo['city'] 				= $addressInfo['city'];
			$orderInfo['district'] 			= $addressInfo['district'];
			$orderInfo['address'] 			= $addressInfo['address'];
			$orderInfo['message'] 			= $order_mes;
			$result = Db::name('mall_order')->where('id', $orderInfo['id'])->update($orderInfo);
			
			if($result){
				return $this -> toJson(200, '', $result);
			}else{
				return $this -> toJson(405, $e);
			}
		}else{
			return $this -> toJson(408, "数据异常");
		}
	}



	/**
	 * 计算商品单价，总价，送积分，需要积分
	 */
	public function getDetailPrice ($goodsInfo,$goods_num){
		
		$goods_lanmu['price'] ="";
		$goods_lanmu['total_price'] ="";
		$goods_lanmu['give_score'] ="";
		$goods_lanmu['needScore'] ="";
		
		//订单总金额
		switch ($goodsInfo['goods_lanmu'])//商品栏目；1：疯狂抢；2：优惠购；3：赚积分；4：云拼团
		{
		case 1:
			$goods_lanmu['price'] 		= $goodsInfo['need_money'];
		 	$goods_lanmu['total_price'] = $goodsInfo['need_money'] * $goods_num;
			$goods_lanmu['give_score'] 	= "";
			$goods_lanmu['needScore'] 	= $goodsInfo['need_money'] * $goods_num;
		  break;  
		case 2:
			$goods_lanmu['price'] 		= $goodsInfo['need_money'];
			$goods_lanmu['total_price'] = $goodsInfo['need_money'] * $goods_num;
			$goods_lanmu['give_score'] 	= "";
			$goods_lanmu['needScore'] 	= $goodsInfo['need_score'] * $goods_num;
		  break;
		case 3:
			$goods_lanmu['price'] 		= $goodsInfo['current_price'];
			$goods_lanmu['total_price'] = $goodsInfo['current_price'] * $goods_num;
			$goods_lanmu['give_score'] 	= $goodsInfo['give_score'] * $goods_num;
			$goods_lanmu['needScore'] 	= "";
		  break;
		case 4:
			$goods_lanmu['price'] 		= $goodsInfo['current_price'];
			$goods_lanmu['total_price'] = $goodsInfo['current_price'] * $goods_num;
			$goods_lanmu['give_score'] 	= $goodsInfo['give_score'] * $goods_num;
			$goods_lanmu['needScore'] 	= "";
		  break;
		default:
			$goods_lanmu = null;
 		  break;
		}
		
		return $goods_lanmu;
	}
	
	
	/**
	 * 添加商品，购物车
	 */
	public function AddOrdercar(){
		$goods_type = request() -> param('goods_type');
		$goods_id = request() -> param('goods_id');
		$user_id = request() -> param('uid');
		
		//获取商品信息
		$goodsTable = $this->getNumType($goods_type);
		$goodsInfo = Db::name($goodsTable)->where('id', $goods_id)->find();
		
		//检查用户是否已经有该商品
		$check['goods_id'] = $goods_id;
		$check['user_id'] = $user_id;
		$goodsCar = Db::name("mall_order_cart")->where($check)->find();
		
		if($goodsCar){
			$result['exist'] = "Y";
			return $this -> toJson(200, '', $result);
		}else{
			
		switch ($goodsInfo['goods_lanmu'])//商品栏目；1：疯狂抢；2：优惠购；3：赚积分；4：云拼团
		{
		case 1:
			$price = $goodsInfo['need_money'];
			$give_score = "";
			$needScore 	= $goodsInfo['need_score'];
			$needMoney  = $goodsInfo['need_money'];
		  break;  
		case 2:
			$price = $goodsInfo['need_money'];
			$give_score = "";
			$needScore 	= $goodsInfo['need_score'];
			$needMoney  = $goodsInfo['need_money'];
		  break;
		case 3:
			$price = $goodsInfo['current_price'];
			$give_score = $goodsInfo['give_score'];
			$needScore 	= "";
			$needMoney  = "";
		  break;
		case 4:
			$price = $goodsInfo['current_price'];
			$give_score = $goodsInfo['give_score'];
			$needScore 	= "";
			$needMoney  = "";
		  break;
		default:
			return "数据异常";
 		  	break;
			exit;
		}
			
			//订单详情信息
			$orderCar = new OrderCarModel();
			$orderCar->goods_id		=  $goodsInfo['id'];
			$orderCar->number		=  1;
			$orderCar->goods_name	=  $goodsInfo['name'];
			$orderCar->price		=  $price;
			$orderCar->weight		=  $goodsInfo['weight'];
			$orderCar->thumb		=  $goodsInfo['thumb'];
			$orderCar->postage		=  $goodsInfo['postage'];
			$orderCar->agent_id		=  $goodsInfo['agent_id'];
			$orderCar->add_time		=  now_time();
			$orderCar->need_score	=  $needScore;
			$orderCar->need_money	=  $needMoney;
			$orderCar->goods_lanmu	=  $goodsInfo['goods_lanmu'];
			$orderCar->user_id		=  $user_id;
			$orderCar->total_price	=  $price;
			$orderCar->give_score	=  $give_score;
			$orderCar->status		=  1;
			
			if($goodsInfo['goods_lanmu']!=2 && $goodsInfo['goods_lanmu']!=3){
				$orderCar->needScore	=  "";
			}else{
				$orderCar->needScore	=  $goodsInfo['need_score'];
			}
			
			$res = $orderCar->allowField(true)->save();
			
			if($res){
				$result['exist'] = "success";
				return $this -> toJson(200, '', $result);
			}
			
		}
	}

	/**
	 * 删除购物车商品
	 */
	public function delOrdercar(){
		$ordercar_ids = request() -> param('ordercar_ids');
		$user_id = request() -> param('user_id');
		
		$ordercar_ids = explode(",", substr($ordercar_ids,0,strlen($ordercar_ids)-1));
		if($ordercar_ids){
			$i = count($ordercar_ids)-1;
			do{
			   $result = Db::name('mall_order_cart')->where('id', $ordercar_ids[$i])->delete();
			   $i--;
			} while ($i >= 0);
		}
		if($result){
			return $this -> toJson(200, '', 'Y');
		}else{
			return $this -> toJson(405, 'N');
		}
		
		
	}
	
	
	/**
	 * 获取用户购物车信息
	 */
	public function getOrdercar(){
		$user_id = request() -> param('user_id');
		
		$orderCarList = Db::name("mall_order_cart")->where(['user_id'=>$user_id,'status'=>1])->select();
		
		if($orderCarList){
			return $this -> toJson(200, '', $orderCarList);
		}else{
			return $this -> toJson(405, '数据异常');
		}
	}
	
	
	/**
	 * 购物车购买操作
	 */
	public function payCart(){
		$goodsIds = request() -> param('cartIds');
		$cartId_num = request() -> param('nums');
		$user_id = request() -> param('user_id');
		$goods_type = request() -> param('goodsTypes');
		
		$goodsIdArray = explode(",", $goodsIds); 
		$numArray = explode(",", $cartId_num); 
		$typeArray = explode(",", $goods_type); 
		
		
		$goodsList= array();
		for($i=0;$i<count($goodsIdArray);$i++){
			$tableName= $this->getNumType($typeArray[$i]);
			$goods = Db::name($tableName)->where('id',$goodsIdArray[$i])->find();
			$goods['buy_num'] = intval($numArray[$i]);
			array_push($goodsList,$goods);
		}
		
		//订单分组
		$items = array();
		foreach($goodsList as $key=>$item) {
			$items[$item['agent_id']][] = $item;
		}
		
		$key_list = array();
		foreach($items as $key=>$item){
			array_push($key_list,$key);
		}
		
		//获取用户信息
		$userInfo = Db::name("member")->where('id', $user_id)->find();
		
		//获取上级代理
		$level2 = Db::name("member")->where('id', $userInfo['pid'])->value('pid');
		$level3 = Db::name("member")->where('id', $level2)->value('pid');
		
		//获取分佣信息
		$site = Db::name("mall_setting")->where("key","distribution")->find();
		$site = iunserializer($site['value']);
		
		
		$suc_orderList = array();
		// 启动事务
		Db::startTrans();
		try{
				foreach($items as $key=>$value){
					//获取店铺合伙人id
					$storeUid = Db::name("mall_agent")->where('id', $key)->value('u_id');
					$pt_id =Db::name("member")->where('id', $storeUid)->value('pt_id');
				
					//生成订单
					$newOrder=new OrderModel();
					$newOrder->agent_id 		= $key;
					$newOrder->order_state 		= 1;
					$newOrder->user_id 			= $user_id;
					$newOrder->order_time 		= now_time();	
					$newOrder->sn 				= order_create_no();
					$newOrder->express_type 	= 1;
					$newOrder->co_id 			= 0;
					$newOrder->pt_id 			= $pt_id;
					$newOrder->level1 			= $userInfo['pid'];
					$newOrder->level2 			= $level2;
					$newOrder->level3 			= $level3;
					$newOrder->is_comment     	= 0;
					
					$result1 = $newOrder->allowField(true)->save();
					$newOrder_id = $newOrder-> id;
					
					
					foreach($value as $k=>$item){
						//获取当前详情价格
						$detail =$this->getDetailPrice($item,$item['buy_num']);
					
						if(!empty($detail)){
							//生成订单详情
							$newItem = new OrderItemsModel();
							$newItem->goods_id		=  $item['id'];
							$newItem->order_id		=  $newOrder_id;
							$newItem->agent_id		=  $item['agent_id'];
							$newItem->goods_name	=  $item['name'];
							$newItem->price			=  $detail['price'];
							$newItem->weight		=  $item['weight'];
							$newItem->number		=  $item['buy_num'];
							$newItem->thumb			=  $item['thumb'];
							$newItem->postage		=  $item['postage'];
							$newItem->add_time		=  now_time();
							$newItem->need_score	=  $detail['needScore'];
							$newItem->goods_lanmu	=  $item['goods_lanmu'];
							$newItem->user_id		=  $user_id;
							$newItem->total_price	=  $detail['total_price'];
							$newItem->give_score	=  $detail['give_score'];
							
							$result2 = $newItem->allowField(true)->save();
						}
						
					}
					
					//根据订单id更新订单数据
					$ItemM = new OrderItemsModel();
 					$sql = "select MAX(postage) as postage,SUM(give_score) as give_score,SUM(need_score) as need_score,SUM(total_price) as total_price from long_mall_order_item where order_id=".$newOrder_id;
    				$resultList = $ItemM->query($sql);
					
					$cuttent_total_price = $resultList[0]['total_price'];
					
					$orderInfo = Db::name('mall_order')->where('id', $newOrder_id)->find();
					
					$orderInfo['total_price'] 		= $cuttent_total_price;
					$orderInfo['postage'] 			= $resultList[0]['postage'];
					$orderInfo['level1_money'] 		= (floatval($site['commission1'])*100 * $cuttent_total_price)/10000;
					$orderInfo['level2_money'] 		= (floatval($site['commission2'])*100 * $cuttent_total_price)/10000;
					$orderInfo['level3_money'] 		= (floatval($site['commission3'])*100 * $cuttent_total_price)/10000;
					$orderInfo['pt_money'] 			= (floatval($site['ptagentcommission'])*100 * $cuttent_total_price)/10000;
					$orderInfo['co_money'] 			= (floatval($site['cityagentcommission'])*100 * $cuttent_total_price)/10000;
					$orderInfo['need_score'] 		= $resultList[0]['need_score'];
					$orderInfo['give_score'] 		= $resultList[0]['give_score'];
					
					$up_order_result = Db::name('mall_order')->where('id', $newOrder_id)->update($orderInfo);
					
					if($up_order_result){
						array_push($suc_orderList,$newOrder_id);
					}else{
						return $this -> toJson(405, '数据异常');
						exit;
					}
					
				}
			// 提交事务
		    Db::commit();
			return $this -> toJson(200,'',$suc_orderList);
		}catch (\Exception $e) {
			Db::rollback();
			return $e;
		}
		
	}
	
	
	public function resultTest(){
		dump(order_create_no());
	}
	
	
	/*
	 *获取用户地址信息
	 */
	public function getAddress(){
		
		$address_id = request() -> param('address_id');
		$address = Db::name('mall_address')->where('id', $address_id)->find();
		if($address){
			return $this -> toJson(200, '', $address);
		}else{
			return $this -> toJson(405, '数据异常');
		}

	}
	
	
		/**
	 * 获取物流信息
	 */
	public function getExpressInfo(){
		$order=db("mall_order")->find(input("id"));
		$model=new OrderModel();
		$status=$model::getText($order['order_state']);
		if (!$order["express"] || !$order["express_no"]) {
			return json(['code'=>406,'msg'=>'错误的快递公司代码或快递单号']);
		}
		$url = "http://www.vshop88.net/phone/express.php?type={$order["express"]}&postid={$order["express_no"]}";
		$data = ihttp_get($url);
		$msg = '';
		if(!empty($data) && !empty($data['content'])) {
			$traces = json_decode($data['content'], true);
			if(is_array($traces)) {
				if($traces['message']) {
					$msg = $traces['message'];
				}
				$traces = $traces['data'];
				if(is_array($traces)) {
					$reply = array();
					foreach($traces as $trace) {
						$reply[] = array(
							'time' => $trace['time'],
							'content' => $trace['context']
						);
					}
					return json(['code'=>200,'msg'=>'','data'=>$reply,'status'=>$status]);
				}
			}
		}
		if (!$msg) {
			return json(['code'=>406,'msg'=>'追踪订单消息失败','status'=>$status]);
		}
	}
	
	
	/**
	 * 获取商品类型
	 */
	 public function getNumType($num){
	 	switch ($num)
		{
		case 2:
		  return "mall_goods_discount";
		  break;  
		case 4:
		   return "mall_goods_pintuan";
		  break;
		case 3:
		   return "mall_goods_score";
		  break;
		case 1:
		   return "mall_goods_grab";
		  break;
		default:
			return null;
		 break;
		}
	}
	
	/**
	 * 获取商品类型
	 */
	 public function getGoodsType($goodsType){
	 	switch ($goodsType)
		{
		case 'discountGoods':
		  return "mall_goods_discount";
		  break;  
		case 'pintuanGoods':
		   return "mall_goods_pintuan";
		  break;
		case 'scoreGoods':
		   return "mall_goods_score";
		  break;
		case 'grabGoods':
		   return "mall_goods_grab";
		  break;
		default:
			return null;
		 break;
		}
	}
	
	
}
